package com.youlai.system.controller;

import com.youlai.system.common.result.PageResult;
import com.youlai.system.common.result.Result;
import com.youlai.system.model.dto.CarouselEditDTO;
import com.youlai.system.model.dto.CarouselInsertDTO;
import com.youlai.system.model.dto.CarouselSelectDTO;
import com.youlai.system.model.vo.CarouselVO;
import com.youlai.system.service.CarouselService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

@Tag(name = "轮播图管理相关接口")
@RestController
@RequestMapping("/api/carousel")
@Slf4j
public class CarouselController {
    @Resource
    private CarouselService carouselService;
    /**
     * 添加轮播图
     * @param carouselInsertDTO
     * @return Result
     */

    @Operation(summary = "新增轮播图")
    @PostMapping("/add")
    public Result<Void> addCarousel(@RequestBody @Valid CarouselInsertDTO carouselInsertDTO) {
        boolean result = carouselService.addCarousel(carouselInsertDTO);
        return Result.judge(result);
    }

    /**
     *  编辑轮播图
     * @param carouselEditDTO
     */
    @Operation(summary = "修改轮播图")
    @PutMapping("/edit")
    public Result<Void> editCarousel(@RequestBody @Valid CarouselEditDTO carouselEditDTO) {
        boolean editCarousel = carouselService.editCarousel(carouselEditDTO);
        return Result.judge(editCarousel);
    }

    /**
     * 删除轮播图应用，将state改为0
     * @param ids
     */
    @Operation(summary = "删除轮播图")
    @DeleteMapping("/delete/{ids}")
    public Result<Void> deleteCarousel(@PathVariable Integer[] ids) {
        boolean result = carouselService.deleteCarousel(ids);
        return Result.judge(result);
    }

    /**
     * 分页查询
     */

    @Operation(summary = "分页查询轮播图")
    @GetMapping("page")
    public PageResult<CarouselVO> getPage(@ParameterObject CarouselSelectDTO carouselSelectDTO)
    {
        return carouselService.getPage(carouselSelectDTO);
    }

    /**
     * 根据id查询轮播图
     */
    @Operation(summary = "根据id查询轮播图")
    @GetMapping("/get/{id}")
    public Result<CarouselVO> getCarouselById(@PathVariable Integer id) {
        CarouselVO carouselVO = carouselService.getCarouselById(id);
        return Result.success(carouselVO);
    }
}
